import { defineStore } from 'pinia';

import { createRepairOrder } from 'src/services/repairService';
import { formatDate } from 'src/utils/dateUtils';
import { CheckInOrder } from 'src/services/type';

export const useCheckinStore = defineStore('useCheckinStore', {
  state: () => ({
    repairOrder: {
      cews_order_no: '',
      stock_code: '',
      serial_no: '',
      work_order_no: '',
      car: '',
      mtce_type: '',
      report_date: '',
      location: '',
      department: '',
      failure_symptom: '',
      description: '',
      remark: '',
      status: '',
      io_counter: '',
      workgroup:'',
      parent_work_order_no: '',
      contractor_liability: '',
      dlc_form_no: '',
      designated_person_name: '',
      date: '',
      line:'',
      line_work_order:'',
      check_in_date:'',
      equipment:'',
      delay_i: '',
      delay_a: '',
      po_no: '',
      inspection_no: '',
      received_date: '',
    } as CheckInOrder,
    igi:{
      po_no: '',
      inspection_no: '',
      received_date: '',
      mtce_type:''
    }
  }),
  getters: {},
  actions: {
    async submit() {
      try {
        const res = await createRepairOrder(this.repairOrder);
        if (res.data) {

          return res.data.qr_code;
        }
      } catch (error) {
        console.log(error);
      }
    },
    clear() {
      this.repairOrder = {
        cews_order_no: '',
        stock_code: '',
        serial_no: '',
        work_order_no: '',
        car: '',
        mtce_type: '',
        report_date: '',
        location: '',
        department: '',
        failure_symptom: '',
        description: '',
        remark: '',
        status: '',
        io_counter: '',
        workgroup:'',
        parent_work_order_no: '',
        contractor_liability: '',
        dlc_form_no: '',
        designated_person_name: '',
        date: '',
        line:'',
        line_work_order:'',
        check_in_date:'',
        equipment:'',
        delay_i: '',
        delay_a: ''
      } as CheckInOrder;
      this.igi ={
        po_no: '',
        inspection_no: '',
        received_date: '',
        mtce_type: ''
      }
    },
  },
});
